/*
 * @Author: yanjikun
 * @Date: 2022-03-22 09:58:51
 * @LastEditors: yanjikun
 * @LastEditTime: 2022-03-22 10:21:16
 * @Description: file content
 */
import dayjs from 'dayjs'

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
const DATE_FORMAT = 'YYYY-MM-DD'
/**
 * @description: 格式化时间为 YYYY-MM-DD HH:mm:ss 或传入参数自定义格式
 * @param {*}
 * @return {*}
 * @author: yanjikun
 */
export const formatToDateTime = (
  date: dayjs.Dayjs | undefined = undefined,
  format = DATE_TIME_FORMAT
): string => {
  return dayjs(date).format(format)
}
/**
 * @description: 格式化时间为 YYYY-MM-DD 或传入参数自定义格式
 * @param {*}
 * @return {*}
 * @author: yanjikun
 */
export const formatToDate = (
  date: dayjs.Dayjs | undefined = undefined,
  format = DATE_FORMAT
): string => {
  return dayjs(date).format(format)
}

export const dateUtil = dayjs
